import itertools

n = int(input('Введите натуральное 4х значное число: '))

l = []

ln = list(str(n))

b = 0

ln = [int(x) for x in ln]

r = 3

if len(str(n)) != 4:
    print(0)
else:
    for i in itertools.combinations(ln, r):
        
        i = [str(x) for x in i]
        
        i = int(''.join(i))
            
        for k in range(2, 3):
            if i % k == 0:
                b += 1
            
        if b == 0:
            l.append(i)
        
        r -= 1

if not l:
    print(0)

else:
    print(max(l))
